package de.tum.in.eist.im.shared.User;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import de.tum.in.eist.im.shared.ChatChannel.ChatChannel;

@SuppressWarnings("serial")
public class User implements Serializable {
	
	// private variables
	private String username = null;
	private String password = null;
	private List<ChatChannel> openChatChannels = new ArrayList<ChatChannel>();
	
	/**
	 * default constructor
	 */
	public User() {}
	
	/**
	 * constructor to create a user object without a password (anonymous user)
	 * @param username the name of the user
	 */
	public User (String username) {
		this.username = username;
		this.password = "";
	}
	
	/**
	 * constructor to create a user object with a password (registered user)
	 * @param username the name of the user
	 * @param password the password of the user
	 */
	public User(String username, String password) {
		this.username = username;
		this.password = password;
	}

	/**
	 * get the username
	 * @return the username
	 */
	public String getUsername() {
		return this.username;
	}
	
	/**
	 * get the password
	 * @return the password
	 */
	public String getPassword() {
		return this.password;
	}
	
	/**
	 * set the password of a user (only used before user object is created for registration reasons)
	 * @param password the password which should be set
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	
	/**
	 * add a chat channel to the user if he is entering this channel
	 * @param chatChannel the chat channel to be added
	 */
	public void addOpenChatChannel(ChatChannel chatChannel) {
		boolean found = false;
		for (ChatChannel cC : openChatChannels) {
			if (cC.getChatId().equals(chatChannel.getChatId()))
				found = true;
		}
		if (!found)
			openChatChannels.add(chatChannel);
	}
	
	/**
	 * TODO: remove open chat channel
	 */
	
	/**
	 * return the list of open chat channels of the user
	 * @return List of open chat channels
	 */
	public List<ChatChannel> getActiveChatChannelsOfUser() {
		return this.openChatChannels;
	}
}
